package se.hh.service;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import se.hh.lab.dao.RecordDao;
import se.hh.lab.dao.impl.RecordDaoImpl;
import se.hh.lab.domain.Login;
import se.hh.lab.domain.Record;

public class UserBorrowed extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		int page =0;
		HttpSession session=request.getSession();
		String userID=request.getParameter("userID");		
		Login login=(Login)session.getAttribute("userlogin");
		if(null==login && userID==null)
		{
			response.sendRedirect("user_login.jsp");
			return;
		}
		if(userID!=null)
		{
			page=Integer.parseInt(request.getParameter("page"));
		}
		if(login!=null)
		{
			userID=login.getUserID();
		}
		
		Integer intPage=page;
		if(intPage==0||intPage==null)
			intPage=1;
		request.setAttribute("userID", userID);
		request.setAttribute("intPage", intPage);	
		Record record=new Record();
		record.setUserID(userID);
		
		RecordDao recordDao=new RecordDaoImpl();
		ArrayList<Record> list=recordDao.getRecord(record,intPage);
		session.setAttribute("list", list);			
		request.getRequestDispatcher("user_borrowed.jsp").forward(request, response);
	
		
		

		
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		this.doGet(request, response);
	}

}
